<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE CPP, DeriveDataTypeable, MagicHash, UnboxedTuples #-}</span><span class="hs-cpp">

#if __GLASGOW_HASKELL__ &gt;= 701
</span><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-7"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- Module      :  Control.Concurrent.STM.TMVar</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2004</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-12"></span><span class="hs-comment">--</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- Stability   :  experimental</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- Portability :  non-portable (requires STM)</span><span>
</span><span id="line-16"></span><span class="hs-comment">--</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- TMVar: Transactional MVars, for use in the STM monad</span><span>
</span><span id="line-18"></span><span class="hs-comment">-- (GHC only)</span><span>
</span><span id="line-19"></span><span class="hs-comment">--</span><span>
</span><span id="line-20"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-21"></span><span>
</span><span id="line-22"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Control.Concurrent.STM.TMVar</span><span> </span><span class="hs-special">(</span><span class="hs-cpp">
#ifdef __GLASGOW_HASKELL__
</span><span>        </span><span class="annot"><span class="hs-comment">-- * TMVars</span></span><span>
</span><span id="line-25"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier">TMVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-26"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#newTMVar"><span class="hs-identifier">newTMVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-27"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#newEmptyTMVar"><span class="hs-identifier">newEmptyTMVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-28"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#newTMVarIO"><span class="hs-identifier">newTMVarIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-29"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#newEmptyTMVarIO"><span class="hs-identifier">newEmptyTMVarIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-30"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#takeTMVar"><span class="hs-identifier">takeTMVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-31"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#putTMVar"><span class="hs-identifier">putTMVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-32"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#readTMVar"><span class="hs-identifier">readTMVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-33"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#tryReadTMVar"><span class="hs-identifier">tryReadTMVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-34"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#swapTMVar"><span class="hs-identifier">swapTMVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-35"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#tryTakeTMVar"><span class="hs-identifier">tryTakeTMVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-36"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#tryPutTMVar"><span class="hs-identifier">tryPutTMVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-37"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#isEmptyTMVar"><span class="hs-identifier">isEmptyTMVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-38"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#mkWeakTMVar"><span class="hs-identifier">mkWeakTMVar</span></a></span><span class="hs-cpp">
#endif
</span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span class="hs-cpp">

#ifdef __GLASGOW_HASKELL__
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-44"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.html#"><span class="hs-identifier">GHC.Conc</span></a></span><span>
</span><span id="line-45"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/GHC.Weak.html#"><span class="hs-identifier">GHC.Weak</span></a></span><span>
</span><span id="line-46"></span><span>
</span><span id="line-47"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Typeable.html#"><span class="hs-identifier">Data.Typeable</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Data.Typeable.Internal.html#Typeable"><span class="hs-identifier">Typeable</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-48"></span><span>
</span><span id="line-49"></span><span class="hs-keyword">newtype</span><span> </span><span id="TMVar"><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-var">TMVar</span></a></span></span><span> </span><span id="local-6989586621679037242"><span class="annot"><a href="#local-6989586621679037242"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="TMVar"><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-var">TMVar</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037242"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679037179"><span id="local-6989586621679037184"><span class="annot"><span class="annottext">TMVar a -&gt; TMVar a -&gt; Bool
(TMVar a -&gt; TMVar a -&gt; Bool)
-&gt; (TMVar a -&gt; TMVar a -&gt; Bool) -&gt; Eq (TMVar a)
forall a. TMVar a -&gt; TMVar a -&gt; Bool
forall a. (a -&gt; a -&gt; Bool) -&gt; (a -&gt; a -&gt; Bool) -&gt; Eq a
/= :: TMVar a -&gt; TMVar a -&gt; Bool
$c/= :: forall a. TMVar a -&gt; TMVar a -&gt; Bool
== :: TMVar a -&gt; TMVar a -&gt; Bool
$c== :: forall a. TMVar a -&gt; TMVar a -&gt; Bool
</span><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var">Eq</span></span></span></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/Data.Typeable.Internal.html#Typeable"><span class="hs-identifier hs-type">Typeable</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-50"></span><span class="hs-comment">{- ^
A 'TMVar' is a synchronising variable, used
for communication between concurrent threads.  It can be thought of
as a box, which may be empty or full.
-}</span><span>
</span><span id="line-55"></span><span>
</span><span id="line-56"></span><span class="hs-comment">-- |Create a 'TMVar' which contains the supplied value.</span><span>
</span><span id="line-57"></span><span id="local-6989586621679037241"><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#newTMVar"><span class="hs-identifier hs-type">newTMVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679037241"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037241"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-58"></span><span id="newTMVar"><span class="annot"><span class="annottext">newTMVar :: forall a. a -&gt; STM (TMVar a)
</span><a href="Control.Concurrent.STM.TMVar.html#newTMVar"><span class="hs-identifier hs-var hs-var">newTMVar</span></a></span></span><span> </span><span id="local-6989586621679037171"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037171"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-59"></span><span>  </span><span id="local-6989586621679037170"><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037170"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; STM (TVar (Maybe a))
forall a. a -&gt; STM (TVar a)
</span><a href="../../base/src/GHC.Conc.Sync.html#newTVar"><span class="hs-identifier hs-var">newTVar</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Maybe a
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037171"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-60"></span><span>  </span><span class="annot"><span class="annottext">TMVar a -&gt; STM (TMVar a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; TMVar a
forall a. TVar (Maybe a) -&gt; TMVar a
</span><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-var">TMVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037170"><span class="hs-identifier hs-var">t</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-61"></span><span>
</span><span id="line-62"></span><span class="hs-comment">-- |@IO@ version of 'newTMVar'.  This is useful for creating top-level</span><span>
</span><span id="line-63"></span><span class="hs-comment">-- 'TMVar's using 'System.IO.Unsafe.unsafePerformIO', because using</span><span>
</span><span id="line-64"></span><span class="hs-comment">-- 'atomically' inside 'System.IO.Unsafe.unsafePerformIO' isn't</span><span>
</span><span id="line-65"></span><span class="hs-comment">-- possible.</span><span>
</span><span id="line-66"></span><span id="local-6989586621679037234"><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#newTMVarIO"><span class="hs-identifier hs-type">newTMVarIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679037234"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037234"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-67"></span><span id="newTMVarIO"><span class="annot"><span class="annottext">newTMVarIO :: forall a. a -&gt; IO (TMVar a)
</span><a href="Control.Concurrent.STM.TMVar.html#newTMVarIO"><span class="hs-identifier hs-var hs-var">newTMVarIO</span></a></span></span><span> </span><span id="local-6989586621679037165"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037165"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-68"></span><span>  </span><span id="local-6989586621679037164"><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037164"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; IO (TVar (Maybe a))
forall a. a -&gt; IO (TVar a)
</span><a href="../../base/src/GHC.Conc.Sync.html#newTVarIO"><span class="hs-identifier hs-var">newTVarIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Maybe a
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037165"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-69"></span><span>  </span><span class="annot"><span class="annottext">TMVar a -&gt; IO (TMVar a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; TMVar a
forall a. TVar (Maybe a) -&gt; TMVar a
</span><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-var">TMVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037164"><span class="hs-identifier hs-var">t</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-70"></span><span>
</span><span id="line-71"></span><span class="hs-comment">-- |Create a 'TMVar' which is initially empty.</span><span>
</span><span id="line-72"></span><span id="local-6989586621679037231"><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#newEmptyTMVar"><span class="hs-identifier hs-type">newEmptyTMVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037231"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-73"></span><span id="newEmptyTMVar"><span class="annot"><span class="annottext">newEmptyTMVar :: forall a. STM (TMVar a)
</span><a href="Control.Concurrent.STM.TMVar.html#newEmptyTMVar"><span class="hs-identifier hs-var hs-var">newEmptyTMVar</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-74"></span><span>  </span><span id="local-6989586621679037160"><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037160"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; STM (TVar (Maybe a))
forall a. a -&gt; STM (TVar a)
</span><a href="../../base/src/GHC.Conc.Sync.html#newTVar"><span class="hs-identifier hs-var">newTVar</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-75"></span><span>  </span><span class="annot"><span class="annottext">TMVar a -&gt; STM (TMVar a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; TMVar a
forall a. TVar (Maybe a) -&gt; TMVar a
</span><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-var">TMVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037160"><span class="hs-identifier hs-var">t</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-76"></span><span>
</span><span id="line-77"></span><span class="hs-comment">-- |@IO@ version of 'newEmptyTMVar'.  This is useful for creating top-level</span><span>
</span><span id="line-78"></span><span class="hs-comment">-- 'TMVar's using 'System.IO.Unsafe.unsafePerformIO', because using</span><span>
</span><span id="line-79"></span><span class="hs-comment">-- 'atomically' inside 'System.IO.Unsafe.unsafePerformIO' isn't</span><span>
</span><span id="line-80"></span><span class="hs-comment">-- possible.</span><span>
</span><span id="line-81"></span><span id="local-6989586621679037229"><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#newEmptyTMVarIO"><span class="hs-identifier hs-type">newEmptyTMVarIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037229"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-82"></span><span id="newEmptyTMVarIO"><span class="annot"><span class="annottext">newEmptyTMVarIO :: forall a. IO (TMVar a)
</span><a href="Control.Concurrent.STM.TMVar.html#newEmptyTMVarIO"><span class="hs-identifier hs-var hs-var">newEmptyTMVarIO</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-83"></span><span>  </span><span id="local-6989586621679037157"><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037157"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; IO (TVar (Maybe a))
forall a. a -&gt; IO (TVar a)
</span><a href="../../base/src/GHC.Conc.Sync.html#newTVarIO"><span class="hs-identifier hs-var">newTVarIO</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-84"></span><span>  </span><span class="annot"><span class="annottext">TMVar a -&gt; IO (TMVar a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; TMVar a
forall a. TVar (Maybe a) -&gt; TMVar a
</span><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-var">TMVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037157"><span class="hs-identifier hs-var">t</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-85"></span><span>
</span><span id="line-86"></span><span class="hs-comment">-- |Return the contents of the 'TMVar'.  If the 'TMVar' is currently</span><span>
</span><span id="line-87"></span><span class="hs-comment">-- empty, the transaction will 'retry'.  After a 'takeTMVar',</span><span>
</span><span id="line-88"></span><span class="hs-comment">-- the 'TMVar' is left empty.</span><span>
</span><span id="line-89"></span><span id="local-6989586621679037227"><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#takeTMVar"><span class="hs-identifier hs-type">takeTMVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037227"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037227"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-90"></span><span id="takeTMVar"><span class="annot"><span class="annottext">takeTMVar :: forall a. TMVar a -&gt; STM a
</span><a href="Control.Concurrent.STM.TMVar.html#takeTMVar"><span class="hs-identifier hs-var hs-var">takeTMVar</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span id="local-6989586621679037153"><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037153"><span class="hs-identifier hs-var">t</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-91"></span><span>  </span><span id="local-6989586621679037152"><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037152"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; STM (Maybe a)
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037153"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-92"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037152"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-93"></span><span>    </span><span class="annot"><span class="annottext">Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">STM a
forall a. STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#retry"><span class="hs-identifier hs-var">retry</span></a></span><span>
</span><span id="line-94"></span><span>    </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679037149"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037149"><span class="hs-identifier hs-var">a</span></a></span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; Maybe a -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037153"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">a -&gt; STM a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037149"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-95"></span><span>
</span><span id="line-96"></span><span class="hs-comment">-- | A version of 'takeTMVar' that does not 'retry'.  The 'tryTakeTMVar'</span><span>
</span><span id="line-97"></span><span class="hs-comment">-- function returns 'Nothing' if the 'TMVar' was empty, or @'Just' a@ if</span><span>
</span><span id="line-98"></span><span class="hs-comment">-- the 'TMVar' was full with contents @a@.  After 'tryTakeTMVar', the</span><span>
</span><span id="line-99"></span><span class="hs-comment">-- 'TMVar' is left empty.</span><span>
</span><span id="line-100"></span><span id="local-6989586621679037222"><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#tryTakeTMVar"><span class="hs-identifier hs-type">tryTakeTMVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037222"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037222"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-101"></span><span id="tryTakeTMVar"><span class="annot"><span class="annottext">tryTakeTMVar :: forall a. TMVar a -&gt; STM (Maybe a)
</span><a href="Control.Concurrent.STM.TMVar.html#tryTakeTMVar"><span class="hs-identifier hs-var hs-var">tryTakeTMVar</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span id="local-6989586621679037143"><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037143"><span class="hs-identifier hs-var">t</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-102"></span><span>  </span><span id="local-6989586621679037142"><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037142"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; STM (Maybe a)
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037143"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-103"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037142"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-104"></span><span>    </span><span class="annot"><span class="annottext">Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; STM (Maybe a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-105"></span><span>    </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679037141"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037141"><span class="hs-identifier hs-var">a</span></a></span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; Maybe a -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037143"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; STM (Maybe a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Maybe a
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037141"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-106"></span><span>
</span><span id="line-107"></span><span class="hs-comment">-- |Put a value into a 'TMVar'.  If the 'TMVar' is currently full,</span><span>
</span><span id="line-108"></span><span class="hs-comment">-- 'putTMVar' will 'retry'.</span><span>
</span><span id="line-109"></span><span id="local-6989586621679037220"><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#putTMVar"><span class="hs-identifier hs-type">putTMVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037220"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679037220"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-110"></span><span id="putTMVar"><span class="annot"><span class="annottext">putTMVar :: forall a. TMVar a -&gt; a -&gt; STM ()
</span><a href="Control.Concurrent.STM.TMVar.html#putTMVar"><span class="hs-identifier hs-var hs-var">putTMVar</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span id="local-6989586621679037137"><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037137"><span class="hs-identifier hs-var">t</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679037136"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037136"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-111"></span><span>  </span><span id="local-6989586621679037135"><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037135"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; STM (Maybe a)
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037137"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-112"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037135"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-113"></span><span>    </span><span class="annot"><span class="annottext">Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; Maybe a -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037137"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Maybe a
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037136"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">() -&gt; STM ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-114"></span><span>    </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">STM ()
forall a. STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#retry"><span class="hs-identifier hs-var">retry</span></a></span><span>
</span><span id="line-115"></span><span>
</span><span id="line-116"></span><span class="hs-comment">-- | A version of 'putTMVar' that does not 'retry'.  The 'tryPutTMVar'</span><span>
</span><span id="line-117"></span><span class="hs-comment">-- function attempts to put the value @a@ into the 'TMVar', returning</span><span>
</span><span id="line-118"></span><span class="hs-comment">-- 'True' if it was successful, or 'False' otherwise.</span><span>
</span><span id="line-119"></span><span id="local-6989586621679037218"><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#tryPutTMVar"><span class="hs-identifier hs-type">tryPutTMVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037218"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679037218"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span></span><span>
</span><span id="line-120"></span><span id="tryPutTMVar"><span class="annot"><span class="annottext">tryPutTMVar :: forall a. TMVar a -&gt; a -&gt; STM Bool
</span><a href="Control.Concurrent.STM.TMVar.html#tryPutTMVar"><span class="hs-identifier hs-var hs-var">tryPutTMVar</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span id="local-6989586621679037130"><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037130"><span class="hs-identifier hs-var">t</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679037129"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037129"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-121"></span><span>  </span><span id="local-6989586621679037128"><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037128"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; STM (Maybe a)
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037130"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-122"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037128"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-123"></span><span>    </span><span class="annot"><span class="annottext">Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; Maybe a -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037130"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Maybe a
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037129"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; STM Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-124"></span><span>    </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; STM Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-125"></span><span>
</span><span id="line-126"></span><span class="hs-comment">-- | This is a combination of 'takeTMVar' and 'putTMVar'; ie. it</span><span>
</span><span id="line-127"></span><span class="hs-comment">-- takes the value from the 'TMVar', puts it back, and also returns</span><span>
</span><span id="line-128"></span><span class="hs-comment">-- it.</span><span>
</span><span id="line-129"></span><span id="local-6989586621679037127"><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#readTMVar"><span class="hs-identifier hs-type">readTMVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037127"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037127"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-130"></span><span id="readTMVar"><span class="annot"><span class="annottext">readTMVar :: forall a. TMVar a -&gt; STM a
</span><a href="Control.Concurrent.STM.TMVar.html#readTMVar"><span class="hs-identifier hs-var hs-var">readTMVar</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span id="local-6989586621679037124"><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037124"><span class="hs-identifier hs-var">t</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-131"></span><span>  </span><span id="local-6989586621679037123"><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037123"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; STM (Maybe a)
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037124"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-132"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037123"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-133"></span><span>    </span><span class="annot"><span class="annottext">Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">STM a
forall a. STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#retry"><span class="hs-identifier hs-var">retry</span></a></span><span>
</span><span id="line-134"></span><span>    </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679037122"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037122"><span class="hs-identifier hs-var">a</span></a></span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a -&gt; STM a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037122"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-135"></span><span>
</span><span id="line-136"></span><span class="hs-comment">-- | A version of 'readTMVar' which does not retry. Instead it</span><span>
</span><span id="line-137"></span><span class="hs-comment">-- returns @Nothing@ if no value is available.</span><span>
</span><span id="line-138"></span><span class="hs-comment">--</span><span>
</span><span id="line-139"></span><span class="hs-comment">-- @since 2.3</span><span>
</span><span id="line-140"></span><span id="local-6989586621679037121"><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#tryReadTMVar"><span class="hs-identifier hs-type">tryReadTMVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037121"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037121"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-141"></span><span id="tryReadTMVar"><span class="annot"><span class="annottext">tryReadTMVar :: forall a. TMVar a -&gt; STM (Maybe a)
</span><a href="Control.Concurrent.STM.TMVar.html#tryReadTMVar"><span class="hs-identifier hs-var hs-var">tryReadTMVar</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span id="local-6989586621679037120"><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037120"><span class="hs-identifier hs-var">t</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; STM (Maybe a)
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037120"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-142"></span><span>
</span><span id="line-143"></span><span class="hs-comment">-- |Swap the contents of a 'TMVar' for a new value.</span><span>
</span><span id="line-144"></span><span id="local-6989586621679037214"><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#swapTMVar"><span class="hs-identifier hs-type">swapTMVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037214"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679037214"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037214"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-145"></span><span id="swapTMVar"><span class="annot"><span class="annottext">swapTMVar :: forall a. TMVar a -&gt; a -&gt; STM a
</span><a href="Control.Concurrent.STM.TMVar.html#swapTMVar"><span class="hs-identifier hs-var hs-var">swapTMVar</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span id="local-6989586621679037116"><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037116"><span class="hs-identifier hs-var">t</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679037115"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037115"><span class="hs-identifier hs-var">new</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-146"></span><span>  </span><span id="local-6989586621679037114"><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037114"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; STM (Maybe a)
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037116"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-147"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037114"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-148"></span><span>    </span><span class="annot"><span class="annottext">Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">STM a
forall a. STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#retry"><span class="hs-identifier hs-var">retry</span></a></span><span>
</span><span id="line-149"></span><span>    </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679037113"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037113"><span class="hs-identifier hs-var">old</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; Maybe a -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037116"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Maybe a
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037115"><span class="hs-identifier hs-var">new</span></a></span><span class="hs-special">)</span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">a -&gt; STM a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037113"><span class="hs-identifier hs-var">old</span></a></span><span>
</span><span id="line-150"></span><span>
</span><span id="line-151"></span><span class="hs-comment">-- |Check whether a given 'TMVar' is empty.</span><span>
</span><span id="line-152"></span><span id="local-6989586621679037212"><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#isEmptyTMVar"><span class="hs-identifier hs-type">isEmptyTMVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037212"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span></span><span>
</span><span id="line-153"></span><span id="isEmptyTMVar"><span class="annot"><span class="annottext">isEmptyTMVar :: forall a. TMVar a -&gt; STM Bool
</span><a href="Control.Concurrent.STM.TMVar.html#isEmptyTMVar"><span class="hs-identifier hs-var hs-var">isEmptyTMVar</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span id="local-6989586621679037109"><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037109"><span class="hs-identifier hs-var">t</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-154"></span><span>  </span><span id="local-6989586621679037108"><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037108"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a) -&gt; STM (Maybe a)
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar (Maybe a)
</span><a href="#local-6989586621679037109"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-155"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037108"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-156"></span><span>    </span><span class="annot"><span class="annottext">Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; STM Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-157"></span><span>    </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; STM Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-158"></span><span>
</span><span id="line-159"></span><span class="hs-comment">-- | Make a 'Weak' pointer to a 'TMVar', using the second argument as</span><span>
</span><span id="line-160"></span><span class="hs-comment">-- a finalizer to run when the 'TMVar' is garbage-collected.</span><span>
</span><span id="line-161"></span><span class="hs-comment">--</span><span>
</span><span id="line-162"></span><span class="hs-comment">-- @since 2.4.4</span><span>
</span><span id="line-163"></span><span id="local-6989586621679037210"><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#mkWeakTMVar"><span class="hs-identifier hs-type">mkWeakTMVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037210"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Weak.html#Weak"><span class="hs-identifier hs-type">Weak</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037210"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span></span><span>
</span><span id="line-164"></span><span id="mkWeakTMVar"><span class="annot"><span class="annottext">mkWeakTMVar :: forall a. TMVar a -&gt; IO () -&gt; IO (Weak (TMVar a))
</span><a href="Control.Concurrent.STM.TMVar.html#mkWeakTMVar"><span class="hs-identifier hs-var hs-var">mkWeakTMVar</span></a></span></span><span> </span><span id="local-6989586621679037107"><span class="annot"><span class="annottext">tmv :: TMVar a
</span><a href="#local-6989586621679037107"><span class="hs-identifier hs-var">tmv</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TMVar.html#TMVar"><span class="hs-identifier hs-type">TMVar</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span id="local-6989586621679037105"><span class="annot"><span class="annottext">TVar# RealWorld (Maybe a)
</span><a href="#local-6989586621679037105"><span class="hs-identifier hs-var">t#</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span id="local-6989586621679037104"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, () #)
</span><a href="#local-6989586621679037104"><span class="hs-identifier hs-var">finalizer</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, Weak (TMVar a) #))
-&gt; IO (Weak (TMVar a))
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><span class="hs-identifier hs-var">IO</span></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, Weak (TMVar a) #))
 -&gt; IO (Weak (TMVar a)))
-&gt; (State# RealWorld -&gt; (# State# RealWorld, Weak (TMVar a) #))
-&gt; IO (Weak (TMVar a))
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679037103"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679037103"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-165"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">TVar# RealWorld (Maybe a)
-&gt; TMVar a
-&gt; (State# RealWorld -&gt; (# State# RealWorld, () #))
-&gt; State# RealWorld
-&gt; (# State# RealWorld, Weak# (TMVar a) #)
</span><span class="hs-identifier hs-var">mkWeak#</span></span><span> </span><span class="annot"><span class="annottext">TVar# RealWorld (Maybe a)
</span><a href="#local-6989586621679037105"><span class="hs-identifier hs-var">t#</span></a></span><span> </span><span class="annot"><span class="annottext">TMVar a
</span><a href="#local-6989586621679037107"><span class="hs-identifier hs-var">tmv</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, () #)
</span><a href="#local-6989586621679037104"><span class="hs-identifier hs-var">finalizer</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679037103"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679037102"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679037102"><span class="hs-identifier hs-var">s1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679037101"><span class="annot"><span class="annottext">Weak# (TMVar a)
</span><a href="#local-6989586621679037101"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679037102"><span class="hs-identifier hs-var">s1</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Weak# (TMVar a) -&gt; Weak (TMVar a)
forall v. Weak# v -&gt; Weak v
</span><a href="../../base/src/GHC.Weak.html#Weak"><span class="hs-identifier hs-var">Weak</span></a></span><span> </span><span class="annot"><span class="annottext">Weak# (TMVar a)
</span><a href="#local-6989586621679037101"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="hs-special">#)</span><span class="hs-cpp">
#endif
</span></pre></body></html>